<script setup>
import { ref } from 'vue'

// 角色数据
const characters = [
  {
    id: 1,
    name: '漩涡鸣人',
    role: '第七代火影',
    village: '木叶隐村',
    clan: '漩涡一族',
    image: 'https://via.placeholder.com/400x500?text=漩涡鸣人',
    description: '木叶隐村的第七代火影，拥有九尾的力量，从小立志成为火影保护村子。通过不懈努力，最终实现了自己的梦想，并成为了保护忍者世界的重要力量。',
    abilities: ['影分身之术', '螺旋丸', '九尾模式', '仙人模式']
  },
  {
    id: 2,
    name: '宇智波佐助',
    role: '复仇者',
    village: '木叶隐村（前）',
    clan: '宇智波一族',
    image: 'https://via.placeholder.com/400x500?text=宇智波佐助',
    description: '宇智波一族的幸存者，为了复仇而离开村子，后来成为保护忍者世界的重要力量。拥有写轮眼和轮回眼的强大瞳术。',
    abilities: ['写轮眼', '千鸟', '天照', '须佐能乎', '轮回眼']
  },
  {
    id: 3,
    name: '春野樱',
    role: '医疗忍者',
    village: '木叶隐村',
    clan: '春野一族',
    image: 'https://via.placeholder.com/400x500?text=春野樱',
    description: '拥有强大医疗能力的忍者，纲手的弟子，后来成为木叶隐村的高层。擅长医疗忍术和怪力。',
    abilities: ['医疗忍术', '怪力', '樱花冲']
  },
  {
    id: 4,
    name: '旗木卡卡西',
    role: '第六代火影',
    village: '木叶隐村',
    clan: '旗木一族',
    image: 'https://via.placeholder.com/400x500?text=旗木卡卡西',
    description: '拷贝忍者卡卡西，曾经是第七班的指导上忍，拥有写轮眼。后来成为第六代火影，为木叶隐村做出了巨大贡献。',
    abilities: ['写轮眼', '雷切', '土遁·土流壁', '神威']
  },
  {
    id: 5,
    name: '宇智波鼬',
    role: '晓组织成员',
    village: '木叶隐村（前）',
    clan: '宇智波一族',
    image: 'https://via.placeholder.com/400x500?text=宇智波鼬',
    description: '为了保护村子而被迫灭族的天才忍者，加入晓组织收集情报。在与弟弟佐助的战斗中去世。',
    abilities: ['写轮眼', '月读', '天照', '须佐能乎']
  },
  {
    id: 6,
    name: '波风水门',
    role: '第四代火影',
    village: '木叶隐村',
    clan: '波风一族',
    image: 'https://via.placeholder.com/400x500?text=波风水门',
    description: '鸣人的父亲，被称为黄色闪光的天才忍者。为了保护村子，将九尾封印在鸣人体内，自己也因此牺牲。',
    abilities: ['飞雷神之术', '螺旋丸', '尸鬼封尽']
  },
  {
    id: 7,
    name: '纲手',
    role: '第五代火影',
    village: '木叶隐村',
    clan: '千手一族',
    image: 'https://via.placeholder.com/400x500?text=纲手',
    description: '传说中的三忍之一，拥有强大的医疗忍术和怪力。曾经担任第五代火影，是木叶隐村的重要领导者。',
    abilities: ['医疗忍术', '怪力', '创造再生', '百豪之术']
  },
  {
    id: 8,
    name: '自来也',
    role: '传说中的三忍',
    village: '木叶隐村',
    clan: '无',
    image: 'https://via.placeholder.com/400x500?text=自来也',
    description: '传说中的三忍之一，鸣人的师父，写了《亲热天堂》系列小说。在调查佩恩的过程中被杀害。',
    abilities: ['仙人模式', '螺旋丸', '火遁·豪火球之术', '通灵术·蛤蟆']
  }
]

// 筛选和搜索功能
const searchTerm = ref('')
const filteredCharacters = ref(characters)

// 监听搜索词变化
searchTerm.value = ''
filteredCharacters.value = characters

const searchCharacter = () => {
  if (!searchTerm.value.trim()) {
    filteredCharacters.value = characters
    return
  }
  
  const term = searchTerm.value.toLowerCase().trim()
  filteredCharacters.value = characters.filter(character => 
    character.name.toLowerCase().includes(term) ||
    character.role.toLowerCase().includes(term) ||
    character.village.toLowerCase().includes(term) ||
    character.clan.toLowerCase().includes(term) ||
    character.description.toLowerCase().includes(term)
  )
}
</script>

<template>
  <div class="characters-container">
    <!-- 页面标题 -->
    <section class="page-header">
      <div class="container">
        <h1 class="page-title">火影忍者角色</h1>
        <p class="page-subtitle">探索《火影忍者》中的主要角色</p>
      </div>
    </section>

    <!-- 搜索和筛选 -->
    <section class="search-section">
      <div class="container">
        <div class="search-bar">
          <input
            type="text"
            v-model="searchTerm"
            @input="searchCharacter"
            placeholder="搜索角色..."
            class="search-input"
          />
          <button class="search-button" @click="searchCharacter">
            搜索
          </button>
        </div>
      </div>
    </section>

    <!-- 角色网格 -->
    <section class="characters-grid-section">
      <div class="container">
        <div class="characters-grid">
          <div v-for="character in filteredCharacters" :key="character.id" class="character-card">
            <div class="character-image-container">
              <img :src="character.image" :alt="character.name" class="character-image" />
            </div>
            <div class="character-details">
              <h2 class="character-name">{{ character.name }}</h2>
              <div class="character-info">
                <div class="info-item">
                  <span class="info-label">身份:</span>
                  <span class="info-value">{{ character.role }}</span>
                </div>
                <div class="info-item">
                  <span class="info-label">所属:</span>
                  <span class="info-value">{{ character.village }}</span>
                </div>
                <div class="info-item">
                  <span class="info-label">家族:</span>
                  <span class="info-value">{{ character.clan }}</span>
                </div>
              </div>
              <div class="character-description">
                {{ character.description }}
              </div>
              <div class="character-abilities">
                <h3 class="abilities-title">能力:</h3>
                <div class="abilities-list">
                  <span v-for="ability in character.abilities" :key="ability" class="ability-tag">
                    {{ ability }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
        
        <!-- 无结果提示 -->
        <div v-if="filteredCharacters.length === 0" class="no-results">
          <p>没有找到匹配的角色</p>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
:root {
  --naruto-orange: #ff6b00;
  --naruto-dark-orange: #d45a00;
  --naruto-blue: #0084ff;
  --naruto-dark-blue: #0066cc;
  --naruto-yellow: #ffd700;
  --naruto-black: #333333;
  --naruto-light-gray: #f5f5f5;
  --naruto-white: #ffffff;
  --naruto-gray: #e0e0e0;
}

.characters-container {
  overflow-x: hidden;
}

/* 页面标题 */
.page-header {
  background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), 
              url('https://via.placeholder.com/1920x500?text=NARUTO') center/cover no-repeat;
  color: var(--naruto-white);
  padding: 4rem 0;
  text-align: center;
}

.page-title {
  font-size: 3rem;
  font-weight: bold;
  margin: 0 0 1rem;
  color: var(--naruto-orange);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.page-subtitle {
  font-size: 1.2rem;
  margin: 0;
  color: var(--naruto-yellow);
}

/* 搜索部分 */
.search-section {
  background-color: var(--naruto-white);
  padding: 2rem 0;
  border-bottom: 1px solid var(--naruto-gray);
}

.search-bar {
  display: flex;
  gap: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

.search-input {
  flex: 1;
  padding: 0.8rem 1.2rem;
  font-size: 1rem;
  border: 2px solid var(--naruto-gray);
  border-radius: 4px;
  outline: none;
  transition: border-color 0.3s ease;
}

.search-input:focus {
  border-color: var(--naruto-orange);
}

.search-button {
  padding: 0.8rem 2rem;
  font-size: 1rem;
  font-weight: 500;
  background-color: var(--naruto-orange);
  color: var(--naruto-white);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.search-button:hover {
  background-color: var(--naruto-dark-orange);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 107, 0, 0.3);
}

/* 角色网格 */
.characters-grid-section {
  background-color: var(--naruto-light-gray);
  padding: 4rem 0;
}

.characters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 2rem;
}

.character-card {
  background-color: var(--naruto-white);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
}

.character-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.character-image-container {
  width: 100%;
  height: 300px;
  overflow: hidden;
  background-color: var(--naruto-gray);
}

.character-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.character-card:hover .character-image {
  transform: scale(1.05);
}

.character-details {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.character-name {
  font-size: 1.8rem;
  color: var(--naruto-orange);
  margin: 0 0 1rem;
  text-align: center;
}

.character-info {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--naruto-gray);
}

.info-item {
  flex: 1;
  min-width: 120px;
}

.info-label {
  font-weight: 500;
  color: var(--naruto-black);
}

.info-value {
  color: var(--naruto-blue);
  margin-left: 0.5rem;
}

.character-description {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--naruto-black);
  margin-bottom: 1.5rem;
  flex: 1;
}

.character-abilities {
  margin-top: auto;
}

.abilities-title {
  font-size: 1.1rem;
  color: var(--naruto-black);
  margin: 0 0 1rem;
}

.abilities-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ability-tag {
  background-color: var(--naruto-blue);
  color: var(--naruto-white);
  padding: 0.3rem 0.8rem;
  border-radius: 16px;
  font-size: 0.85rem;
  font-weight: 500;
}

/* 无结果提示 */
.no-results {
  text-align: center;
  padding: 4rem;
  color: var(--naruto-black);
}

.no-results p {
  font-size: 1.2rem;
  margin: 0;
}

/* 容器样式 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-title {
    font-size: 2.5rem;
  }
  
  .page-subtitle {
    font-size: 1rem;
  }
  
  .search-bar {
    flex-direction: column;
  }
  
  .search-button {
    width: 100%;
  }
  
  .characters-grid {
    grid-template-columns: 1fr;
  }
  
  .character-info {
    flex-direction: column;
  }
  
  .info-item {
    min-width: auto;
  }
}

@media (max-width: 480px) {
  .page-title {
    font-size: 2rem;
  }
  
  .character-name {
    font-size: 1.5rem;
  }
  
  .character-image-container {
    height: 250px;
  }
}
</style>